package com.eb.service;

import com.eb.mapper.MiaoshaGoodsMapper;
import com.eb.dao.MiaoshaGoodsDao;
import com.eb.pojo.MiaoshaGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class MiaoshaService {
    @Autowired
    private MiaoshaGoodsMapper miaoshaGoodsMapper;
    @Autowired
    private MiaoshaGoodsDao miaoshaGoodsDao;

    public List<MiaoshaGoods> list() {

        return miaoshaGoodsMapper.selectByExample(null);
    }

    public Page<Map<String, Object>> miaoshaGoods(String goodsName, String start, String end, int page, int size) {
        return miaoshaGoodsDao.miaoshaGoods("%"+goodsName+"%",start,end, PageRequest.of(page-1,size));
    }

    public void MiaoshaAdd(MiaoshaGoods miaoshaGoods) {
        miaoshaGoodsMapper.insert(miaoshaGoods);
    }

    public void del(int id) {
        long b=(long) id;
        miaoshaGoodsMapper.deleteByPrimaryKey(b);
    }

    public void UpdateMiaosha(MiaoshaGoods miaoshaGoods) {

        miaoshaGoodsMapper.updateByPrimaryKey(miaoshaGoods);
    }

    public MiaoshaGoods findByid(int id) {
        long b=(long) id;
        return miaoshaGoodsMapper.selectByPrimaryKey(b);
    }
}
